home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / vastar.c < prev    next >
C/C++ Source or Header  |  2000-04-04  |  7KB  |  280 lines

  1. /***************************************************************************
  2.  
  3.   vidhrdw.c
  4.  
  5.   Functions to emulate the video hardware of the machine.
  6.  
  7. ***************************************************************************/
  8.  
  9. #include "driver.h"
  10. #include "vidhrdw/generic.h"
  11.  
  12.  
  13.  
  14. unsigned char *vastar_bg1colorram2, *vastar_sprite_priority;
  15. unsigned char *vastar_fgvideoram,*vastar_fgcolorram1,*vastar_fgcolorram2;
  16. unsigned char *vastar_bg2videoram,*vastar_bg2colorram1,*vastar_bg2colorram2;
  17. unsigned char *vastar_bg1scroll,*vastar_bg2scroll;
  18. static unsigned char *dirtybuffer2;
  19. static struct osd_bitmap *tmpbitmap2;
  20.  
  21.  
  22.  
  23. void vastar_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
  24. {
  25.     int i;
  26.  
  27.  
  28.     for (i = 0;i < Machine->drv->total_colors;i++)
  29.     {
  30.         int bit0,bit1,bit2,bit3;
  31.  
  32.         /* red component */
  33.         bit0 = (color_prom[0] >> 0) & 0x01;
  34.         bit1 = (color_prom[0] >> 1) & 0x01;
  35.         bit2 = (color_prom[0] >> 2) & 0x01;
  36.         bit3 = (color_prom[0] >> 3) & 0x01;
  37.         *(palette++) =  0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  38.         /* green component */
  39.         bit0 = (color_prom[Machine->drv->total_colors] >> 0) & 0x01;
  40.         bit1 = (color_prom[Machine->drv->total_colors] >> 1) & 0x01;
  41.         bit2 = (color_prom[Machine->drv->total_colors] >> 2) & 0x01;
  42.         bit3 = (color_prom[Machine->drv->total_colors] >> 3) & 0x01;
  43.         *(palette++) =  0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  44.         /* blue component */
  45.         bit0 = (color_prom[2*Machine->drv->total_colors] >> 0) & 0x01;
  46.         bit1 = (color_prom[2*Machine->drv->total_colors] >> 1) & 0x01;
  47.         bit2 = (color_prom[2*Machine->drv->total_colors] >> 2) & 0x01;
  48.         bit3 = (color_prom[2*Machine->drv->total_colors] >> 3) & 0x01;
  49.         *(palette++) =  0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  50.  
  51.         color_prom++;
  52.     }
  53. }
  54.  
  55.  
  56.  
  57. /***************************************************************************
  58.  
  59.   Start the video hardware emulation.
  60.  
  61. ***************************************************************************/
  62. int vastar_vh_start(void)
  63. {
  64.     if (generic_vh_start() != 0)
  65.         return 1;
  66.  
  67.     if ((dirtybuffer2 = malloc(videoram_size)) == 0)
  68.     {
  69.         generic_vh_stop();
  70.         return 1;
  71.     }
  72.     memset(dirtybuffer2,1,videoram_size);
  73.  
  74.     if ((tmpbitmap2 = osd_create_bitmap(Machine->drv->screen_width,Machine->drv->screen_height)) == 0)
  75.     {
  76.         free(dirtybuffer2);
  77.         generic_vh_stop();
  78.         return 1;
  79.     }
  80.  
  81.     return 0;
  82. }
  83.  
  84.  
  85.  
  86. /***************************************************************************
  87.  
  88.   Stop the video hardware emulation.
  89.  
  90. ***************************************************************************/
  91. void vastar_vh_stop(void)
  92. {
  93.     osd_free_bitmap(tmpbitmap2);
  94.     free(dirtybuffer2);
  95.     generic_vh_stop();
  96. }
  97.  
  98.  
  99.  
  100. WRITE_HANDLER( vastar_bg1colorram2_w )
  101. {
  102.     if (vastar_bg1colorram2[offset] != data)
  103.     {
  104.         dirtybuffer[offset] = 1;
  105.  
  106.         vastar_bg1colorram2[offset] = data;
  107.     }
  108. }
  109.  
  110. WRITE_HANDLER( vastar_bg2videoram_w )
  111. {
  112.     if (vastar_bg2videoram[offset] != data)
  113.     {
  114.         dirtybuffer2[offset] = 1;
  115.  
  116.         vastar_bg2videoram[offset] = data;
  117.     }
  118. }
  119.  
  120. WRITE_HANDLER( vastar_bg2colorram1_w )
  121. {
  122.     if (vastar_bg2colorram1[offset] != data)
  123.     {
  124.         dirtybuffer2[offset] = 1;
  125.  
  126.         vastar_bg2colorram1[offset] = data;
  127.     }
  128. }
  129.  
  130. WRITE_HANDLER( vastar_bg2colorram2_w )
  131. {
  132.     if (vastar_bg2colorram2[offset] != data)
  133.     {
  134.         dirtybuffer2[offset] = 1;
  135.  
  136.         vastar_bg2colorram2[offset] = data;
  137.     }
  138. }
  139.  
  140.  
  141. void vastar_draw_sprites(struct osd_bitmap *bitmap)
  142. {
  143.     int offs;
  144.  
  145.  
  146.     /* Draw the sprites. Note that it is important to draw them exactly in this */
  147.     /* order, to have the correct priorities. */
  148.     for (offs = 0; offs < spriteram_size; offs += 2)
  149.     {
  150.         int code;
  151.  
  152.  
  153.         code = ((spriteram_3[offs] & 0xfc) >> 2) + ((spriteram_2[offs] & 0x01) << 6)
  154.                 + ((offs & 0x20) << 2);
  155.  
  156.         if (spriteram_2[offs] & 0x08)    /* double width */
  157.         {
  158.             drawgfx(bitmap,Machine->gfx[2],
  159.                     code/2,
  160.                     spriteram[offs+1] & 0x3f,
  161.                     spriteram_3[offs] & 0x02,spriteram_3[offs] & 0x01,
  162.                     spriteram_3[offs + 1],224-spriteram[offs],
  163.                     &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  164.             /* redraw with wraparound */
  165.             drawgfx(bitmap,Machine->gfx[2],
  166.                     code/2,
  167.                     spriteram[offs+1] & 0x3f,
  168.                     spriteram_3[offs] & 0x02,spriteram_3[offs] & 0x01,
  169.                     spriteram_3[offs + 1],256+224-spriteram[offs],
  170.                     &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  171.         }
  172.         else
  173.             drawgfx(bitmap,Machine->gfx[1],
  174.                     code,
  175.                     spriteram[offs+1] & 0x3f,
  176.                     spriteram_3[offs] & 0x02,spriteram_3[offs] & 0x01,
  177.                     spriteram_3[offs + 1],240-spriteram[offs],
  178.                     &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  179.     }
  180. }
  181.  
  182.  
  183. /***************************************************************************
  184.  
  185.   Draw the game screen in the given osd_bitmap.
  186.   Do NOT call osd_update_display() from this function, it will be called by
  187.   the main emulation engine.
  188.  
  189. ***************************************************************************/
  190. void vastar_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  191. {
  192.     int offs;
  193.  
  194.  
  195.     /* for every character in the Video RAM, check if it has been modified */
  196.     /* since last time and update it accordingly. */
  197.     for (offs = videoram_size - 1;offs >= 0;offs--)
  198.     {
  199.         if (dirtybuffer[offs])
  200.         {
  201.             int sx,sy;
  202.  
  203.  
  204.             dirtybuffer[offs] = 0;
  205.  
  206.             sx = offs % 32;
  207.             sy = offs / 32;
  208.  
  209.             drawgfx(tmpbitmap,Machine->gfx[3],
  210.                     videoram[offs] + 256 * (vastar_bg1colorram2[offs] & 0x01),
  211.                     colorram[offs],
  212.                     0,0,
  213.                     8*sx,8*sy,
  214.                     0,TRANSPARENCY_NONE,0);
  215.         }
  216.  
  217.         if (dirtybuffer2[offs])
  218.         {
  219.             int sx,sy;
  220.  
  221.  
  222.             dirtybuffer2[offs] = 0;
  223.  
  224.             sx = offs % 32;
  225.             sy = offs / 32;
  226.  
  227.             drawgfx(tmpbitmap2,Machine->gfx[4],
  228.                     vastar_bg2videoram[offs] + 256 * (vastar_bg2colorram2[offs] & 0x01),
  229.                     vastar_bg2colorram1[offs],
  230.                     0,0,
  231.                     8*sx,8*sy,
  232.                     0,TRANSPARENCY_NONE,0);
  233.         }
  234.     }
  235.  
  236.  
  237.     /* copy the temporary bitmaps to the screen */
  238.     {
  239.         int scroll[32];
  240.  
  241.  
  242.         for (offs = 0;offs < 32;offs++)
  243.             scroll[offs] = -vastar_bg2scroll[offs];
  244.         copyscrollbitmap(bitmap,tmpbitmap2,0,0,32,scroll,&Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  245.  
  246.         if (*vastar_sprite_priority == 2)
  247.         {
  248.             vastar_draw_sprites(bitmap);    /* sprite must appear behind background */
  249.             copyscrollbitmap(bitmap,tmpbitmap2,0,0,32,scroll,&Machine->drv->visible_area,TRANSPARENCY_COLOR,92);
  250.         }
  251.         else if (*vastar_sprite_priority == 0)
  252.             vastar_draw_sprites(bitmap);
  253.  
  254.         for (offs = 0;offs < 32;offs++)
  255.             scroll[offs] = -vastar_bg1scroll[offs];
  256.         copyscrollbitmap(bitmap,tmpbitmap,0,0,32,scroll,&Machine->drv->visible_area,TRANSPARENCY_COLOR,0);
  257.     }
  258.  
  259.  
  260.     /* draw the frontmost playfield - they are characters, but draw them as sprites */
  261.     for (offs = videoram_size - 1;offs >= 0;offs--)
  262.     {
  263.         int sx,sy;
  264.  
  265.  
  266.         sx = offs % 32;
  267.         sy = offs / 32;
  268.  
  269.         drawgfx(bitmap,Machine->gfx[0],
  270.                 vastar_fgvideoram[offs] + 256 * (vastar_fgcolorram2[offs] & 0x01),
  271.                 vastar_fgcolorram1[offs],
  272.                 0,0,
  273.                 8*sx,8*sy,
  274.                 &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  275.     }
  276.  
  277.     if (*vastar_sprite_priority == 3)
  278.         vastar_draw_sprites(bitmap);
  279. }
  280.